package tree;

/**
 * @author : Rookie
 * @description : 二叉搜索树
 * @date : 2023/10/26
 */
public class BinarySearchTree {

    public static void main(String[] args) {
        int[] input = new int[] {9,8,12,6,-1,11,15};
        TreeNode root = BinaryTreeUtil.buildTree(input);
        int target = 12;
        TreeNode treeNode = search(root, target);
        System.out.println(treeNode);
    }

    private static TreeNode search(TreeNode node,int target) {
        if (node == null || target == node.element) return node;
        if (target < node.element) {
            return search(node.left,target);
        } else {
            return search(node.right,target);
        }
    }
}
